package com.hung.thread;

public class DaemonTestDemo
{
    public static void main(String[] args)
    {
        Thread thread = new Thread(new Runnable()
        {

            @Override
            public void run()
            {
                try
                {
                    System.out.println("in user thread ,Thread.currentThread().isDaemon() = " + Thread.currentThread().isDaemon());
                    Thread.sleep(1000);
                }
                catch (InterruptedException e)
                {
                    e.printStackTrace();
                }
                finally
                {
                    System.out.println("DaemonThread finally run");
                }
            }});
        thread.setDaemon(true);
        Thread thread2 = new Thread(new Runnable()
        {

            @Override
            public void run()
            {
                try
                {
                    System.out.println("in user thread2 ,Thread.currentThread().isDaemon() = " + Thread.currentThread().isDaemon());
                    Thread.sleep(1000);
                }
                catch (InterruptedException e)
                {
                    e.printStackTrace();
                }
                finally
                {
                    System.out.println("DaemonThread finally run");
                }
            }});
        thread2.setDaemon(true);
        thread2.start();
        thread.start();
        System.out.println("in main thread ,Thread.currentThread().isDaemon() = " + Thread.currentThread().isDaemon());
        System.out.println("main Thread");
    }
}